package com.mangowang.module.main.ui;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import com.google.protobuf.InvalidProtocolBufferException;
import com.mangowang.lib.common.base.BaseActivity;
import com.mangowang.lib.common.help.GlideHelper;
import com.mangowang.lib.common.help.UserHelper;
import com.mangowang.lib.common.net.Apis;
import com.mangowang.lib.common.net.NetworkManager;
import com.mangowang.lib.common.net.interfaces.OnRequestCallBack;
import com.mangowang.lib.common.proto.Memberinviter;
import com.mangowang.lib.common.proto.Transfer;
import com.mangowang.lib.common.util.StatusBarUtil;
import com.mangowang.lib.common.util.StringUtil;
import com.mangowang.module.main.R;
import com.mangowang.module.main.R2;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class QrActivity extends BaseActivity {


    @BindView(R2.id.tv_name)
    TextView tv_name;
    @BindView(R2.id.iv_head)
    ImageView iv_head;
    @BindView(R2.id.iv_qr)
    ImageView iv_qr;
    @BindView(R2.id.tv_phone)
    TextView tv_phone;
    @BindView(R2.id.tv_title)
    TextView tv_title;

    @BindView(R2.id.back_iv)
    ImageView backIv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qr);
        ButterKnife.bind(this);
        backIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        StatusBarUtil.setStatusBarLightMode(this, Color.parseColor("#F3F3F3"), true);
        initView();
    }

    private void initView() {
        tv_name.setText(UserHelper.getUser().getTruename());
        tv_phone.setText(StringUtil.PhoneToPass(UserHelper.getUser().getMember_mobile()));
        GlideHelper.INSTANCE.loadAvatar(mContext,iv_head, UserHelper.getUser().getMember_avatar());
        tv_title.setText("二维码");

        NetworkManager.INSTANCE.post(Apis.get_my_qrcode_inviter, new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) throws InvalidProtocolBufferException {
                Memberinviter.get_my_qrcode_inviter  data =  Memberinviter.get_my_qrcode_inviter.parseFrom(response);
                tv_name.setText(data.getMemberName());
                GlideHelper.INSTANCE.loadImage(mContext,iv_qr,data.getQrcodeUrl());
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
//                showToast(errorMessage);
            }
        });

    }
}